using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.ComponentModel;

namespace produccion.clases
{

    class CLSENCPRCP : ObservableObject
    {

MDOgeneral mod = new MDOgeneral();

#region Metodos basicos tabla

//Consulta los procesos por los que ha pasado una orden de produccion por operario
public DataTable consCatPro()
{
    try
    {
        //string query = "select CODPRC_EPP,''||FECREP_EPP||'' as FECREP_EPP,CODOPE_EPP,(select NOMEMP_EMP from MAEEMPP where CODEMP_EMP=CODOPE_EPP) as NOMEMP_EMP,sum(CANPRO_DPP) as CANPRO_DPP  from encprcp,detprcp where NROORD_DPP=NROORD_EPP and CODPRC_DPP=CODPRC_EPP and CONSEC_DPP=CONSEC_EPP and NROORD_EPP='" + NROORD_EPP + "' group by CODPRC_EPP,FECREP_EPP,CODOPE_EPP";
        string query = "select CODPRC_EPP as Proceso,''||FECREP_EPP||'' as Fecha,CODOPE_EPP as Codigo,(select NOMEMP_EMP from MAEEMPP where CODEMP_EMP=CODOPE_EPP) as Nombre,sum(CANPRO_DPP) as Cantidad  from encprcp,detprcp where NROORD_DPP=NROORD_EPP and CODPRC_DPP=CODPRC_EPP and CONSEC_DPP=CONSEC_EPP and NROORD_EPP='" + NROORD_EPP + "' group by CODPRC_EPP,FECREP_EPP,CODOPE_EPP";
        return mod.consulta(query);
    }
    catch (Exception ex) { throw ex; }
}

//Consulta los procesos por los ha pasado una orden de produccion
public DataTable consCantProceso() 
{
    try 
    {
        string query = "select FN_NombreProcesoProd(upper(b.codprc_epp)) as codprc_dpp,''||b.fecrep_epp||'' as fecrep_epp, fn_DuracionProcesoOrden(b.nroord_epp, b.codprc_epp) as dias, sum(a.canpro_dpp) as canpro_dpp from detprcp a inner join encprcp b on a.nroord_dpp=b.nroord_epp and a.codprc_dpp=b.codprc_epp and a.consec_dpp=b.consec_epp where b.nroord_epp='" + NROORD_EPP + "' group by b.nroord_epp, b.codprc_epp, b.fecrep_epp order by b.fecrep_epp asc";
        return mod.consulta(query);
    }
    catch (Exception ex) { throw ex; }
}


public int Insertar(string Ord, string PRC, int Consecutivo, string Fec, string Ope)
{
    try
    {
        string query = "insert into encprcp(nroord_epp,codprc_epp,consec_epp,fecrep_epp,codope_epp) values ('" + Ord + "','" + PRC + "'," + Consecutivo + ",'" + Fec + "','" + Ope + "')";
        return mod.comando(query);
    }
    catch (Exception ex) { throw ex; }
}

#endregion

#region  Propiedades
    private string _NROORD_EPP;
    public string NROORD_EPP
    {
        get { return _NROORD_EPP; }
        set { _NROORD_EPP = value; RaisePropertyChangedEvent("NROORD_EPP"); }
    }

    private string _CODPRC_EPP;
    public string CODPRC_EPP
    {
        get { return _CODPRC_EPP; }
        set 
        {
            if (_CODPRC_EPP != value) { CAMBIO = true; }
            _CODPRC_EPP = value;
            RaisePropertyChangedEvent("CODPRC_EPP");
        }
    }
    private int _CONSEC_EPP;
    public int CONSEC_EPP
    {
        get { return _CONSEC_EPP; }
        set
        {
            if (_CONSEC_EPP != value) { CAMBIO = true; }
            _CONSEC_EPP = value;
            RaisePropertyChangedEvent("CONSEC_EPP");
        }
    }
    private DateTime _FECREP_EPP;
    public DateTime FECREP_EPP
    {
        get { return _FECREP_EPP; }
        set
        {
            if (_FECREP_EPP != value) { CAMBIO = true; }
            _FECREP_EPP = value;
            RaisePropertyChangedEvent("FECREP_EPP");
        }
    }
    private string _CODOPE_EPP;
    public string CODOPE_EPP
    {
        get { return _CODOPE_EPP; }
        set
        {
            if (_CODOPE_EPP != value) { CAMBIO = true; }
            _CODOPE_EPP = value;
            RaisePropertyChangedEvent("CODOPE_EPP");
        }
    }
    private Boolean _CAMBIO = false;
    public Boolean CAMBIO
    {
        get { return _CAMBIO; }
        set { _CAMBIO = value; RaisePropertyChangedEvent("CAMBIO"); }
    }
    private Boolean _EXISTE = false;
    public Boolean EXISTE
    {
        get { return _EXISTE; }
        set { _EXISTE = value; RaisePropertyChangedEvent("EXISTE");
        }
    }
#endregion

      }
}
